package ru.ipccenter.jshell.frontend.compiler;

import javax.tools.FileObject;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject.Kind;
import javax.tools.SimpleJavaFileObject;
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings({ "unchecked" })
public class MemoryFileManager extends ShellFileManager {

  private Map<String, MemoryByteCode> outputMap = new HashMap<String, MemoryByteCode>();


  MemoryFileManager(JavaCompiler compiler) {
    
    super(compiler.getStandardFileManager(null, null, null));
  }
  
  @Override
  public SimpleJavaFileObject getJavaFileForOutput(Location location, String name, Kind kind, FileObject source) {
    
      MemoryByteCode memoryClass = new MemoryByteCode(name, kind);
      getOutputMap().put(name, memoryClass);
      return memoryClass;
  }
  
  public Map<String, MemoryByteCode> getOutputMap() {
    
    return outputMap;
  }
}

